package cur.nature.admin.dao;

import cur.nature.admin.common.config.DBAdminConfig;
import cur.nature.admin.model.po.Admin_ResourcePO;
import cur.nature.admin.model.vo.Admin_ResourceVO;
import cur.nature.framework.mvc.crud.CrudDao;

import cur.nature.framework.core.util.StringUtil;
import cur.nature.tinyorm.core.template.DefaultJdbcTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 菜单分类表 Dao
 * 作者：Auto Generator By wujian
 * 生成日期：2023-07-09 17:46:21
 */
@Component
@DependsOn(DefaultJdbcTemplate.TEMPLATE)
public class Admin_ResourceDao extends CrudDao<Admin_ResourcePO, Admin_ResourceVO> {
    public Admin_ResourceDao(@Qualifier(DBAdminConfig.TEMPLATE) DefaultJdbcTemplate template) {
        super( Admin_ResourcePO.class, Admin_ResourceVO.class, template);
    }

//    public PageBean<Admin_ResourceVO.Base> list(Admin_ResourceVO.list_Param param) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException {
//        StringBuilder condition = new StringBuilder(" 1=1 ");
////        if(StringUtil.isNotEmpty(param.getKeyword())){
////            condition.append(" and a.code like '"+param.getKeyword()+"%'");
////        }
//        String sql = "select " + this.cols() + " from " + tableName() + " a " + " where " + condition;
//        PageBean<Admin_ResourceVO.Base> list = getTemplate().queryForPage(sql, param.buildPage(),
//                null, Admin_ResourceVO.Base.class);
//        return list;
//    }

    public List<Admin_ResourceVO> queryByCond(Admin_ResourceVO.list_Param param) throws Exception {
        // 过滤条件
        final StringBuilder cond = new StringBuilder();
        if (StringUtil.isNotEmpty(param.getKeyword())) {
            cond.append(" and name like '"+param.getKeyword()+"%'");
        }
        // 查询出所有的资源
        List<Admin_ResourceVO> list = queryByCond(cond.toString());
        return list;
    }

}

